-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: early exit for fail() #322
Conversation
src/halmos/exceptions.py
Outdated
@@ -20,6 +20,22 @@ class NotConcreteError(HalmosException): | |||
pass | |||
|
|||
|
|||
class HalmosTargetReached(Exception): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please feel free to suggest a better name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it sounds a little too semantically charged for me, I would go for something more descriptive like RunEndingException(Exception)
, and I would make both HalmosException
and FailCheatcode
inherit from RunEndingException
:
class RunEndingException(Exception):
"""
Base class for any exception that should not just stop the current EVM context, instead aborting the current test run.
"""
pass
class HalmosException(RunEndingException):
"""
Base class for unexpected internal errors happening during a test run.
Inherits from RunEndingException because it should not just stop the current EVM context, but stop the whole run.
"""
pass
class FailCheatcode(RunEndingException):
"""
Raised when invoking DSTest's fail() pseudo-cheatcode.
Inherits from RunEndingException because it should not just stop the current EVM context, but stop the whole run.
"""
pass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some alternatives along the same idea:
- AbortCallException (not great,
Call
is ambiguous there) - AbortTestException
- TestStopException
- RunHaltException (
Halt
is neat) - HaltAndCatchFireException if you don't mind a fun reference 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for suggestion! i ended up with PathEndingException
, because "run" is ambiguous with the entire test run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, love it
fail(); | ||
} | ||
|
||
function check_early_fail_cheatcode(uint x) public { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice test 👍
fix fail() to exit early.
previously, fail() was treated as a normal evm exception, allowing execution to continue after returning to the caller if any. (see the new test as example.) such continued execution is unnecessary. now fail() exits immediately, avoiding potential performance degradation.